using System;
using Framework;
using UnityEngine;
using UnityEngine.UI;

namespace GameCore
{
    public class LevelUI : MonoBehaviour
    {
        public bool isActive = false;

        public Button btn_ShowMenu;
        public GameObject pan_Menu;

        public Button btn_ResumeGame;
        public Button btn_ForceEvacuate;
        public Button btn_Settings;
        public Button btn_SaveAndQuit;
        
        private void Start()
        {
            PlayerInputHandler.AddKeyDownListener(KeyCode.Escape, ToggleActiveState);
            btn_ShowMenu.onClick.AddListener(() => SetActive(true));
            btn_ResumeGame.onClick.AddListener(() => SetActive(false));
            btn_Settings.interactable = false;
            btn_ForceEvacuate.onClick.AddListener(ForceEndAdventure);
            btn_SaveAndQuit.onClick.AddListener(() =>
            {
                LevelManager.Save();
                GameManager.LoadScene("MainMenu");
            });
        }

        private void ToggleActiveState()
        {
            SetActive(!isActive);
        }

        private void ForceEndAdventure()
        {
            LevelManager.EndAdventure(false);
        }

        private void SetActive(bool active)
        {
            pan_Menu.SetActive(active);
            if (active) PlayerInputHandler.Block(this);
            else PlayerInputHandler.Unblock(this);
            isActive = active;
        }
    }
}